<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>配置管理</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script language="javascript" type="text/javascript">
var saveCounter=0;

Ext.onReady(function() {

	var formPanel = new Ext.form.FormPanel({
		layout: 'form',
		border: false,
		bodyStyle: 'padding:5px 5px 5px 5px;',
		frame: false,
		autoWidth: false,
		autoScroll: false,
		labelAlign: 'right',
		labelWidth: 55,
		defaults: {
			anchor: '100%',
			allowBlank: false,
			msgTarget: 'qtip',
			validateOnBlur: false
		},
		items: [{
			name: 'id',
			xtype: 'hidden'
		},{
			fieldLabel: '名称',
			name: 'name',
			xtype: 'textfield',
			maxLength: 64
		},{
			fieldLabel: '键',
			name: 'key',
			xtype: 'textfield'
		},{  
			fieldLabel: '值',
			name: 'value',  
			xtype: 'textfield'
		},{
			fieldLabel: '备注',
			name: 'memo',  
			xtype: 'textarea',
			allowBlank: true
		}],
		bbar: [{
			text: '保存',
			iconCls: 'acceptBtn',
			handler: function(thiz,eventObject) {
				if(!formPanel.getForm().isValid()) {
					return false;
				}
				var action;
				var id='${id}';
				var isUpdate=!Ext.isEmpty(id)&&id!='null';
				if(isUpdate) {
					action='updateJSON';
				}else {
					action='insertJSON';
				}
				formPanel.getForm().doAction('submit',{
					url: '${ctx}/keyValue!'+action+'.action',
					method: 'post',
					waitTitle: ' ',
				    waitMsg: '正在提交数据, 请稍候 ... ...',
					params: {},
					failure: function(form, action) {
						Ext.Msg.hide();
			        	Common.parseFailureResponse(action.response);
					},
					success: function(form, action) {
						var result=action.result;
						Common.parse(result,function(buttonId) {
							Ext.Msg.hide();
							if(result.pass||buttonId=='yes') {
								if(result.attributes&&result.attributes.id) {
									formPanel.find("name","id")[0].setValue(result.attributes.id);
								}
								++saveCounter;
							}
						});
					}
				});
			}
		},'-',{
			text: '取消',
			iconCls: 'delete2Btn',
			handler: function(thiz,eventObject) {
				var winId='${winId}';
				var closeWin=Ext.WindowMgr.get(winId);
				if(closeWin==null){
					closeWin=parent.Ext.WindowMgr.get(winId);
				}
				if(closeWin==null){
					window.returnValue=(saveCounter>0);
					window.close();
				}else{
					closeWin.returnValue=(saveCounter>0);
					closeWin.close();
				}
			}
		}],
		listeners: {
			afterRender: function(thiz){
				var id='${id}';
				if(!Ext.isEmpty(id)&&id!='null'){
					var url='${ctx}/keyValue!getJSON.action';
					var params={
						id: id
					};
					Common.loadForm(thiz,url,params);
				}
			}
		}
	});
	
	var viewport = new Ext.Viewport({
		layout: 'fit',
		border: false,
		items: [formPanel]
	});
});
</script>
</head>

<body>
</body>
</html>